package com.icepeach.icepeachhomeback.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@ApiModel(
        value = "api返回对象",
        description = "通用api返回对象"
)
public class ApiPageResult<T> {
    private static final Logger log = LogManager.getLogger(ApiPageResult.class);
    public static final int CODE_SUCCESS = 200;
    public static final int CODE_BAD_REQUEST = 400;
    public static final int CODE_UNAUTHORIZED = 401;
    public static final int CODE_FORBIDDEN = 403;
    public static final int CODE_NOT_FOUND = 404;
    public static final int CODE_SERVER_ERROR = 500;
    public static final int CODE_NO_LICENSE = 600;
    @ApiModelProperty(
            value = "状态码",
            name = "code",
            example = "1000"
    )
    private int code;
    @ApiModelProperty(
            value = "执行结果信息",
            name = "执行结果信息",
            example = "新增成功"
    )
    private String message;
    @ApiModelProperty(
            value = "结果数据集",
            name = "结果数据集",
            example = "具体结果的json值"
    )
    private ApiPage<T> data;

    private ApiPageResult(int code, String message, ApiPage<T> data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private ApiPageResult() {
    }

    public static <T> ApiPageResult normal(int code, String message, ApiPage<T> data) {
        return new ApiPageResult(code, message, data);
    }

    public static <T> ApiPageResult success(String message, ApiPage<T> data) {
        return normal(200, message, data);
    }

    public static <T> ApiPageResult success(ApiPage<T> data) {
        return normal(200, (String) null, data);
    }

    public static ApiPageResult success() {
        return normal(200, (String) null, (ApiPage) null);
    }

    public static ApiPageResult success(String message) {
        return normal(200, message, (ApiPage) null);
    }

    public static <T> ApiPageResult failure(String message, ApiPage<T> data) {
        return normal(500, message, data);
    }

    public static ApiPageResult failure(String message) {
        return normal(500, message, (ApiPage) null);
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public ApiPage<T> getData() {
        return this.data;
    }
}
